package com.zc.study.thread.多线程第四章节.thread4_1_4;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Services {
    private Lock lock=new ReentrantLock();
    private Condition condition = lock.newCondition();
    public void aWait(){
        try {
        lock.lock();
        System.out.println(Thread.currentThread().getName()+"begin await");
            condition.await();
            System.out.println("await end");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
    public void singal(){
        lock.lock();
        System.out.println("singal start");
        condition.signal();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("singal end");
        lock.unlock();

    }
}
